// Package sysin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.11
package sysin

import (
	"context"
	"hotgo/internal/consts"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"
	"hotgo/utility/validate"

	"github.com/gogf/gf/v2/encoding/gjson"
	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// ProductUpdateFields 修改商品中心字段过滤
type ProductUpdateFields struct {
	Name              string      `json:"name"              dc:"商品名称"`
	Type              int         `json:"type"              dc:"商品属性"`
	MainImage         *gjson.Json `json:"mainImage"         dc:"商品主图"`
	BenefitPoints     *gjson.Json `json:"benefitPoints"     dc:"商品利益点"`
	Integral          float64     `json:"integral"          dc:"积分价格"`
	IntegralLogistics float64     `json:"integralLogistics" dc:"物流价格"`
	CostPrice         float64     `json:"costPrice"         dc:"成本价"`
	SalePrice         float64     `json:"salePrice"         dc:"销售价"`
	MarketPrice       float64     `json:"marketPrice"       dc:"市场价格"`
	Scene             int         `json:"scene"             dc:"适用场景"`
	StoreId           string      `json:"storeId"           dc:"门店"`
	Description       string      `json:"description"       dc:"描述"`
	Images            string      `json:"images"            dc:"配图"`
	RestrictionType   int         `json:"restrictionType"   dc:"限购"`
	Cycle             int         `json:"cycle"             dc:"时间周期"`
	QuantityLimit     int         `json:"quantityLimit"     dc:"数量限制"`
	SalesType         int         `json:"salesType"         dc:"销氪/服务人员信息"`
	AgentId           int64       `json:"agentId"           dc:"销氪ID"`
	Rules             string      `json:"rules"             dc:"规则说明"`
	VipProportion     int         `json:"vipProportion"     dc:"会员利润分配比例(%)"`
}

// ProductInsertFields 新增商品中心字段过滤
type ProductInsertFields struct {
	Name              string      `json:"name"              dc:"商品名称"`
	Type              int         `json:"type"              dc:"商品属性"`
	MainImage         *gjson.Json `json:"mainImage"         dc:"商品主图"`
	BenefitPoints     *gjson.Json `json:"benefitPoints"     dc:"商品利益点"`
	Integral          float64     `json:"integral"          dc:"积分价格"`
	IntegralLogistics float64     `json:"integralLogistics" dc:"物流价格"`
	CostPrice         float64     `json:"costPrice"         dc:"成本价"`
	SalePrice         float64     `json:"salePrice"         dc:"销售价"`
	MarketPrice       float64     `json:"marketPrice"       dc:"市场价格"`
	Scene             int         `json:"scene"             dc:"适用场景"`
	StoreId           string      `json:"storeId"           dc:"门店"`
	Description       string      `json:"description"       dc:"描述"`
	Images            string      `json:"images"            dc:"配图"`
	RestrictionType   int         `json:"restrictionType"   dc:"限购"`
	Cycle             int         `json:"cycle"             dc:"时间周期"`
	QuantityLimit     int         `json:"quantityLimit"     dc:"数量限制"`
	SalesType         int         `json:"salesType"         dc:"销氪/服务人员信息"`
	AgentId           int64       `json:"agentId"           dc:"销氪ID"`
	Rules             string      `json:"rules"             dc:"规则说明"`
	VipProportion     int         `json:"vipProportion"     dc:"会员利润分配比例(%)"`
}

// ProductEditInp 修改/新增商品中心
type ProductEditInp struct {
	entity.Product
}

func (in *ProductEditInp) Filter(ctx context.Context) (err error) {
	// 验证商品名称
	if err := g.Validator().Rules("required").Data(in.Name).Messages("商品名称不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证商品属性
	if err := g.Validator().Rules("required").Data(in.Type).Messages("商品属性不能为空").Run(ctx); err != nil {
		return err.Current()
	}
	if err := g.Validator().Rules("in:1,2,3").Data(in.Type).Messages("商品属性值不正确").Run(ctx); err != nil {
		return err.Current()
	}

	return
}

type ProductEditModel struct{}

// ProductViewInp 获取指定商品中心信息
type ProductViewInp struct {
	Id int64 `json:"id" v:"required#ID不能为空" dc:"ID"`
}

func (in *ProductViewInp) Filter(ctx context.Context) (err error) {
	return
}

type ProductViewModel struct {
	entity.Product
}

// ProductListInp 获取商品中心列表
type ProductListInp struct {
	form.Sorters
	form.PageReq
	ID        int64  `json:"id" dc:"ID"`
	Type      int    `json:"type"    dc:"商品类型"`
	Name      string `json:"name"   dc:"商品名称"`
	Status    int    `json:"status" dc:"商品状态"`
	Adcode    string `json:"adcode" dc:"区域编码"`
	StoreName string `json:"storeName" dc:"门店名称"`
}

func (in *ProductListInp) Filter(ctx context.Context) (err error) {
	return
}

type ProductListModel struct {
	Id            int64       `json:"id"        dc:"ID"`
	Name          string      `json:"name"      dc:"商品名称"`
	Type          int         `json:"type"      dc:"商品属性"`
	CreatedAt     *gtime.Time `json:"createdAt" dc:"上线时间"`
	Status        int         `json:"status"    dc:"商品状态"`
	Scene         int         `json:"scene"     dc:"适用场景"`
	CostPrice     float64     `json:"costPrice" dc:"成本价"`
	SalePrice     float64     `json:"salePrice" dc:"销售价"`
	Integral      float64     `json:"integral"  dc:"积分价格"`
	MarketPrice   float64     `json:"marketPrice" dc:"市场价格"`
	StoreName     string      `json:"storeName" dc:"门店名称"`
	MainImage     *gjson.Json `json:"mainImage" dc:"商品主图"`
	VipProportion int         `json:"vipProportion"     dc:"会员利润分配比例(%)"`
}

// ProductStatusInp 更新商品中心状态
type ProductStatusInp struct {
	Id     int64 `json:"id" v:"required#ID不能为空" dc:"ID"`
	Status int   `json:"status" dc:"状态"`
}

func (in *ProductStatusInp) Filter(ctx context.Context) (err error) {
	if in.Id <= 0 {
		err = gerror.New("ID不能为空")
		return
	}

	if in.Status <= 0 {
		err = gerror.New("状态不能为空")
		return
	}

	if !validate.InSlice(consts.StatusSlice, in.Status) {
		err = gerror.New("状态不正确")
		return
	}
	return
}

type ProductStatusModel struct{}
